package com.dhl.responseibilitychain;

import com.dhl.responseibilitychain.approver.CollegeApprover;
import com.dhl.responseibilitychain.approver.DepartmentApporver;
import com.dhl.responseibilitychain.approver.SchoolMasterApprover;
import com.dhl.responseibilitychain.approver.ViceSchoolMasterApprover;

/**
 * @title: Client
 * @Author danghailiang
 * @Date: 2022/8/24 1:54
 * @Version 1.0
 */
public class Client {
    public static void main(String[] args) {
        // 新建审批单子
        PurchaseRequest purchaseRequest = new PurchaseRequest();
        purchaseRequest.setId(1);
        purchaseRequest.setPrice(11000);
        purchaseRequest.setType(1);

        // 创建审批人责任链
        DepartmentApporver departmentApporver = new DepartmentApporver("班主任");
        SchoolMasterApprover schoolMasterApprover = new SchoolMasterApprover("校长");
        ViceSchoolMasterApprover viceSchoolMasterApprover = new ViceSchoolMasterApprover("副校长");
        CollegeApprover collegeApprover = new CollegeApprover("院长");

        // 形成链表, departmentApporver --->>> collegeApprover --->>> viceSchoolMasterApprover --->>> schoolMasterApprover --->>> departmentApporver
        departmentApporver.setApprover(collegeApprover);
        collegeApprover.setApprover(viceSchoolMasterApprover);
        viceSchoolMasterApprover.setApprover(schoolMasterApprover);
        schoolMasterApprover.setApprover(departmentApporver);

        // 开始审批
        collegeApprover.processRequest(purchaseRequest);
    }
}
